package pers.muci.es.index;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * @ClassName IndexCreate
 * @Description TODO
 * @Author muci
 * @Date 2021/12/21 21:44
 * @Version 1.0
 **/
public class IndexCreate {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("106.14.15.56", 9200, "http"))
        );

        CreateIndexRequest user = new CreateIndexRequest("user");

        CreateIndexResponse createIndexResponse = client.indices().create(user, RequestOptions.DEFAULT);
        //响应状态
        boolean acknowledged = createIndexResponse.isAcknowledged();
        System.out.println("索引操作： " + acknowledged);

        client.close();
    }

}
